package com.graduate.examapp.view.activity

import android.content.Context
import android.media.MediaPlayer
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import com.graduate.examapp.R
import com.graduate.examapp.databinding.ActivityAlarmBinding
import com.graduate.examapp.databinding.ActivityLoginBinding
import com.graduate.examapp.service.Store
import com.graduate.examapp.view.base.BaseActivity
import java.time.LocalTime
import java.time.format.DateTimeFormatter

/**
 * 闹钟Activity
 */
class AlarmActivity : AppCompatActivity() {
    private val gotItClickHandle = View.OnClickListener {
        Store.ringtone?.let {
            if (it.isPlaying) {
                it.stop()
            }
        }
        this.finish()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding: ActivityAlarmBinding =
            DataBindingUtil.setContentView(this, R.layout.activity_alarm)
        binding.lifecycleOwner = this

        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
        //window.setBackgroundDrawable(windowBackgroud)
        window.setBackgroundDrawable(getDrawable(R.drawable.alarm_bg))
        var originVisibility: Int = window.decorView.getSystemUiVisibility()
        originVisibility = originVisibility xor View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
        window.decorView.systemUiVisibility =  originVisibility

        val alarmMessage = intent.getStringExtra("alarm_message")
        findViewById<TextView>(R.id.alarm_message).text = alarmMessage
        val dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm")
        findViewById<TextView>(R.id.time).text = LocalTime.now().format(dateTimeFormatter)
        binding.gotItHandle = gotItClickHandle
    }

    override fun onStart() {
        super.onStart()
        //mediaPlayer?.start()
    }
}